let rec power x n =
 
  if n < 0 then 
    invalid_arg "puissance negative"
  else

  match n with 
     0 -> 1
    |_ -> x * power x (n-1);;

power 1 2;;

(* ------------------ *)

let rec application list x =
  
  match list with 
    [] -> 0
   |(a,n)::l -> (a * power x n) + application l x;;

application [(2,2);(2,3);(4,4)] 2;;

(* ------------------ *)

let rec add list list2 =

  match (list,list2) with

    ([],[]) -> []
    |([],(a,b)::list) -> (a,b)::list
    |((a,b)::list,[]) -> (a,b)::list

      (* Si le degre est le meme *)
    |((a,b)::list,(x,y)::list2) when b=y ->
	(a+x,b):: add list list2

      (* sinon *)
    |((a,b)::list,(x,y)::list2) ->
      if b<y then
       (a,b)::(x,y):: add list list2
      else 
       (x,y)::(a,b):: add list list2 ;;

add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

(* ------------------ *)

let rec soustract list list2 =

 match (list,list2) with

    ([],[]) -> []
    |([],(a,b)::list) -> (a,b)::list
    |((a,b)::list,[]) -> (a,b)::list

      (* Si le degre est le meme *)
    |((a,b)::list,(x,y)::list2) when b=y ->
	(a-x,b):: soustract list list2

      (* sinon *)
    |((a,b)::list,(x,y)::list2) ->
      if b<y then
       (a,b)::(-x,y):: soustract list list2
      else 
       (-x,y)::(a,b):: soustract list list2 ;;

soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

(* ------------------ *)

let rec deriv list =

  match list with 
      [] -> []
     |(a,b)::list -> (b*a,b-1):: deriv list ;;

deriv [(2,2);(2,3);(4,4)];;

(* -- Fin de la page -- *)
